/**
 * 
 */
package due.pc.pcshoot.entity;

import org.anddev.andengine.entity.sprite.AnimatedSprite;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;

import due.pc.pcshoot.gamelogic.IEnemyLogicHandler;

/**
 * @author manhhung.vu
 *
 */
public abstract class BaseEnemy extends AnimatedSprite implements IEnemy
{
	//===============================================================/
	//Constants
	//===============================================================/
	
	
	//===============================================================/
	//Fields
	//===============================================================/
	protected long mAppearTime;
	protected int mScore;
	
	protected EnemyState mState;
	
	protected IEnemyLogicHandler mLogicHandler;
	
	//===============================================================/
	//Constructors
	//===============================================================/
	public BaseEnemy(
			float pX, float pY, 
			float pTileWidth, float pTileHeight,
			TiledTextureRegion pTiledTextureRegion) 
	{
		super(pX, pY, pTileWidth, pTileHeight, pTiledTextureRegion);
		setVisible(false);
		mState = EnemyState.READY;
	}

	//===============================================================/
	//Inherited Methods
	//===============================================================/
	
	@Override
	public void setState(
			EnemyState pState, float pBallVelocityX,
			float pBallVelocityY, float pCanonFiredPointX,
			float pCanonFiredPointY) 
	{
		if (mLogicHandler != null) mLogicHandler.applyFiredInfo(pBallVelocityX, pBallVelocityY, pCanonFiredPointX, pCanonFiredPointY);
		setState(pState);
	}
	
	//===============================================================/
	//Methods
	//===============================================================/
	

	//===============================================================/
	//Setters & Getters
	//===============================================================/
	@Override
	public void setLogicHandler(IEnemyLogicHandler pLogicHandler) {
		mLogicHandler = pLogicHandler;
	}
	
	@Override
	public IEnemyLogicHandler getLogicHandler() {
		return mLogicHandler;
	}
	
	
	public long getAppearTime() {
		return mAppearTime;
	}
	
	public void setAppearTime(long pAppearTime) {
		mAppearTime = pAppearTime;
	}
	
	public int getScore() {
		return mScore;
	}
	
	public void setScore(int pScore) {
		mScore = pScore;
	}
	
	public EnemyState getState() {
		return mState;
	}
	
	public void setState(EnemyState pState) {
		mState = pState;
		if (mLogicHandler != null) {
			mLogicHandler.onEnemyStateChanged(pState, this);
		}
	}
	
	public float getCenterX() {
		return getSceneCenterCoordinates()[0];
	}
	
	public float getCenterY() {
		return getSceneCenterCoordinates()[1];
	}
	
	
	//===============================================================/
	//Static
	//===============================================================/
}
